const CONFIG = require('./config.js')
const API_BASE_URL = 'https://api.it120.cc'

const request = (url, needSubDomain, method, data) => {
  let _url = API_BASE_URL + (needSubDomain ? '/' + CONFIG.subDomain : '') + url
  return new Promise((resolve, reject) => {
    wx.request({
      url: _url,
      method: method,
      data: data,
      header: {
        'content-type':'application/x-www-form-urlencoded'
      },
      success(res){
        resolve(res.data)
      },
      fail(err){
        reject(err)
      },
      complete(data) {
        // 加载完成
      }
    })
  })
}


module.exports = {
  request,
  banners: (data) => {
    return request('/banner/list', true, 'get', data)
  },
  shopinfo:(data) => {
    return request('/shop/subshop/list', true, 'post', data)
  },
  good: (data) => {
    return request('/shop/goods/list', true, 'post', data)
  },
  goodArticle: (data) => {
    return request('/shop/goods/detail', true, 'get', data)
  },
  goodsDetail: (id) => {
    return request('/shop/goods/detail', true, 'get', {
      id
    })
  },
  queryConfigBatch: (keys) => {
    return request('/config/values', true, 'get', { keys })
  },
  // 获取菜品类型
  goodsCategory: () => {
    return request('/shop/goods/category/all', true, 'get')
  },
}
